'use strtic';

let index_fn = async (ctx,next)=>{
    ctx.body = `
    <title>登录</title>
    <p>
    <h1 style="text-align: center;">登录页面</h1>
    <h1 style="text-align: center;">账号是admin 密码是123</h1>
    <h1 style="text-align: center;">账号是pd 密码是123</h1>
    <h1 style="text-align: center;">账号是laohu 密码是123</h1>
    <h1 style="text-align: center;">以上任选一个</h1>
    </p>
    <form action="/loginjudge" method="POST">
        <p style="text-align: center;">用户名：<input type="text" name="username" id=""></p>
        <p style="text-align: center;">密码：<input type="password" name="password" id=""></p>
        <p style="text-align: center;"><input type="submit" value="登录" name="" id=""></p>
    </form>`;
};
let loginjudge_fn = async (ctx,next)=>{
    var username = ctx.request.body.username || '';
    var password = ctx.request.body.password || '';
    if((username === 'admin' && password === '123')||(username === 'pd' && password === '123')||(username === 'laohu' && password === '123')){
        ctx.render('hello.html',{nickname:`你好${username}`});
    }else{
        ctx.render('hello.html',{nickname:`小老弟，账号或密码错误，重新再试一下吧`});
    }
}
module.exports={
    "/":["get",index_fn],
    "/loginjudge":["post",loginjudge_fn]
}